package com.qzw.study.xml;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;

import java.util.Iterator;
import java.util.Map;

/**
 * @author ：quziwei
 * @date ：2020/8/13 1:26
 * @description：Bean工厂后置处理器
 */
@Configuration
public class SelfBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		Map<String, Object> beansWithAnnotation = beanFactory.getBeansWithAnnotation(Controller.class);
		beansWithAnnotation.forEach((name,bean) -> {
			BeanDefinition beanDefinition = beanFactory.getBeanDefinition(name);
			beanDefinition.setAutowireCandidate(false);
		});


	}


}
